package com.lbt.mybatis.plus.extend.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.lbt.mybatis.plus.extend.interceptor.DefaultExtendInnerInterceptor;
import com.lbt.mybatis.plus.extend.interceptor.ExtendInnerInterceptor;
import com.lbt.mybatis.plus.extend.json.MybatisPlusExtendJsonDeserializer;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

/**
 * @author zhangjinyu
 * @since 2023-05-16
 */
@AutoConfiguration
@ComponentScan("com.lbt.mybatis.plus.extend")
public class MybatisPlusExtendConfig {

    @Bean
    @ConditionalOnMissingBean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        return new MybatisPlusInterceptor();
    }

    @Bean
    @ConditionalOnMissingBean
    public ExtendInnerInterceptor extendInnerInterceptor(MybatisPlusInterceptor mybatisPlusInterceptor) {
        ExtendInnerInterceptor extendInnerInterceptor = new DefaultExtendInnerInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(extendInnerInterceptor);
        return extendInnerInterceptor;
    }

    @Bean
    @ConditionalOnMissingBean
    public MybatisPlusExtendJsonDeserializer mybatisPlusExtendJsonDeserializer() {
        throw new IllegalArgumentException("请完成MybatisPlusExtendJsonDeserializer的依赖注入");
    }
}
